package ${packageName}.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * ${tableInfo.tableComment}
 * 
 * @author ${tableInfo.author}
 * @date ${.now?string("yyyy-MM-dd")}
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("${tableInfo.tableName}")
public class ${tableInfo.className} {
    
<#list tableInfo.columns as column>
    /**
     * ${column.columnComment}
     */
    <#if column.isPrimaryKey>
    @TableId(value = "${column.columnName}", type = IdType.AUTO)
    <#else>
    @TableField("${column.columnName}")
    </#if>
    private ${getJavaType(column.columnType)} ${getFieldName(column.columnName)};
    
</#list>
    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    
    /**
     * 逻辑删除标志（0：未删除，1：已删除）
     */
    @TableLogic
    @TableField("deleted")
    private Integer deleted;
}

<#function getJavaType dbType>
    <#switch dbType?lower_case>
        <#case "varchar">
        <#case "char">
        <#case "text">
        <#case "longtext">
            <#return "String">
        <#case "int">
        <#case "integer">
            <#return "Integer">
        <#case "bigint">
            <#return "Long">
        <#case "decimal">
        <#case "numeric">
        <#case "double">
            <#return "Double">
        <#case "float">
            <#return "Float">
        <#case "boolean">
        <#case "tinyint">
            <#return "Boolean">
        <#case "datetime">
        <#case "timestamp">
            <#return "LocalDateTime">
        <#case "date">
            <#return "LocalDate">
        <#case "time">
            <#return "LocalTime">
        <#default>
            <#return "String">
    </#switch>
</#function>

<#function getFieldName columnName>
    <#assign fieldName = columnName?lower_case>
    <#assign parts = fieldName?split("_")>
    <#assign result = parts[0]>
    <#list parts as part>
        <#if part_index gt 0>
            <#assign result = result + part?cap_first>
        </#if>
    </#list>
    <#return result>
</#function> 